home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Language/OS - Multiplatform Resource Library
/
LANGUAGE OS.iso
/
forth
/
amiga
/
amigaker.arc
/
09.loading
< prev
next >
Wrap
Text File
|
1987-12-30
|
4KB
|
115 lines
;
; 09.loading
;
; File loading.
; Loading a file requires, besides a fib, an input buffer. These buffers
; hold the line to be loaded, and must be unique if nested loading is used.
; The buffers are created and kept in a single linked list last in first out
; The variable lb points to the top.
* newlb (s -- ) Get a load buffer, 256 bytes long, links it into
; the linked list pointed to by lb, aborts if out of memory.
dc.w -1
dc.l doslink2
doslink2 set *-4
dc.b $85,'newl',$80!'b'
cnop 0,2
_newlb dc.l nest
dc.l _2,_nest_lit,256,_AllocMem
dc.l _dup,_0_equal,_nest_abort_quote
dc.b 30,'Unable to allocate loadbuffer',0
cnop 0,2
dc.l _lb,_fetch,_over,_store,_lb,_store
dc.l _exit
* droplb (s -- ) Unlink top load buffer from the list and
; discard it.
dc.w -1
dc.l doslink0
doslink0 set *-4
dc.b $86,'dropl',$80!'b'
cnop 0,2
_droplb dc.l nest
dc.l _lb,_fetch,_question_dup,_question_branch,1$
dc.l _dup,_fetch,_lb,_store
dc.l _nest_lit,256,_FreeMem
1$ dc.l _exit
* getline (s addr len -- addr 'len ) Same as gets, but substitutes
; blanks for cr's. Ignores lines consisting of only a cr. Note that each
; line is expected to be terminated by a cr.
dc.w -1
dc.l doslink3
doslink3 set *-4
dc.b $87,'getlin',$80!'e'
cnop 0,2
_getline dc.l nest
dc.l _2dup
1$ dc.l _2drop,_2dup,_gets
dc.l _dup,_1,_not_equals,_question_branch,1$
dc.l _2swap,_2drop
dc.l _dup,_question_branch,3$
dc.l _2dup,_plus,_1_minus,_dup,_c_fetch
dc.l _nest_lit,10,_equals,_question_branch,2$
dc.l _bl,_swap,_c_store,_branch,3$
2$ dc.l _drop
3$ dc.l _exit
* #loadline A variable, 250 by default, but can be set to e.g. 64
; to load files consisting of blocks.
dc.w -1
dc.l doslink3
doslink3 set *-4
dc.b $89,'#loadlin',$80!'e'
cnop 0,2
_number_loadline dc.l docreate,250
* question (s -- n ) Works the same as query, but loads from a file
; n will be zero if end of file is reached.
dc.w -1
dc.l doslink1
doslink1 set *-4
dc.b $88,'questio',$80!'n'
cnop 0,2
_question dc.l nest
dc.l _lb,_fetch,_4_plus,_1_plus
dc.l _number_loadline,_fetch
dc.l _getline,_tuck,_swap,_1_minus,_c_store
dc.l _to_in,_off,_exit
* (load) (s fib -- ) Loads the file at fib, all input is taken from
; the file until an end of file is found, nesting is possible.
dc.w 0
dc.l link0
link0 set *-4
dc.b $86,$28,'load',$80!$29
cnop 0,2
_nest_load dc.l nest
dc.l _question_define
dc.l _dup,_file_open
dc.l _newlb
dc.l _1,_loading,_plus_store
dc.l _in_file,_to_r,_tick_in_file,_store
dc.l _to_in,_fetch,_to_r
1$ dc.l _question,_question_branch,2$
dc.l _run,_branch,1$
2$ dc.l _r_from,_to_in,_store
dc.l _in_file,_file_close,_r_from,_tick_in_file,_store
dc.l _minus_1,_loading,_plus_store,_droplb,_exit
* load Load is deferred word, usually set to (load).
dc.w 0
dc.l link0
link0 set *-4
dc.b $84,'loa',$80!'d'
cnop 0,2
_load dc.l dodefer,_nest_load